﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using GrayParrot.Configuration;
using GrayParrot.Caching.Configuration;

namespace GrayParrot.Caching
{
    public abstract class CacheBase
    {
        private ConfigurationManagerHelper m_configuration = null;

        public ConfigurationManagerHelper Configuration
        {
            get 
            {
                if (m_configuration == null)
                {
                    m_configuration = new ConfigurationManagerHelper();
                }

                return m_configuration; 
            }
        }

        public CacheBase()
        {
            Initialize();
        }

        public abstract void Initialize();

        protected TimeSpan InitializeExpirationPeriod()
        {
            TimeSpan retValue = new TimeSpan(0, 10, 0);  // default is 10 minutes
            
            //ConfigurationManagerHelper cmh = new ConfigurationManagerHelper();
            ExpirationPeriod m_period = m_configuration.GetExpirationPeriod();
            int m_time = m_configuration.GetExpirationTime();

            switch (m_period)
            {
                case ExpirationPeriod.Seconds:
                    retValue = new TimeSpan(0, 0, 0, m_time);
                    break;
                case ExpirationPeriod.Minutes:
                    retValue = new TimeSpan(0, 0, m_time, 0);
                    break;
                case ExpirationPeriod.Hours:
                    retValue = new TimeSpan(0, m_time, 0, 0);
                    break;
                case ExpirationPeriod.Days:
                    retValue = new TimeSpan(m_time, 0, 0, 0);
                    break;
                default:
                    break;
            }

            return retValue;
        }
    }
}
